#include<cstdio>//uncle-lu
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

struct node{
	int x, y;
};
node line[210];
int F[210][210];
int n;

int main()
{
	read(n);
	for (int i = 1; i <= n; i++) 
	{
		read(line[i].x);
		line[i+n].x = line[i].x;
	}
	for (int i = 1; i <= 2*n-1; i++) 
		line[i].y = line[i+1].x;
	line[2*n].y = line[1].x;

	for (int len = 1; len <= n; len++) 
	{
		for (int l = 1; l <= 2*n - len + 1; l++) 
		{
			int r = l + len - 1;
			for (int k = l; k <= r-1; k++) 
				F[l][r] = std::max(F[l][r], F[l][k] + F[k+1][r] + line[l].x * line[k].y * line[r].y);
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) 
		ans = std::max(ans, F[i][i+n-1]);

	printf("%d", ans);
	return 0;
}
